package com.ht.controller;

import cn.hutool.json.JSONUtil;
import com.ht.data.Result;
import com.ht.dto.UserDTO;
import com.ht.service.CollectionService;
import com.ht.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("collection")
@Api("科普号收藏管理Api")
@RefreshScope //自动刷新配置文件
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    @GetMapping
    @ApiOperation(value = "根据登录用户去查询收藏")
    public Result findCollectionByUser(@RequestHeader("AuthToken")String token){
        Claims claims = new JwtUtil().parseJwt(token);
        UserDTO userDTO = JSONUtil.toBean(claims.getSubject(), UserDTO.class);
        Result result = collectionService.findCollectionByUserId(userDTO.getId());
        return result;
    }

}
